
import 'package:flutter/material.dart';
import 'package:xim/common/get_style_view.dart';
import 'package:xim/http/apis/user/user_api.dart';

import 'account_login_page_controller.dart';
import 'account_login_page_style.dart';

class AccountLoginPage extends GetStyleControllerView<void, AccountLoginPageController, AccountLoginPageStyle>{
  AccountLoginPage({super.key});

  @override
  Widget buildView(BuildContext context, void data) {
    return Scaffold(
      appBar: style.appBar,
        body: Container(
          padding: const EdgeInsets.symmetric(horizontal: 12),
          child: SingleChildScrollView(
            child: Column(
                children: [
                  style.logo,
                  const SizedBox(height: 20,),
                  TextField(
                    maxLines: 1,
                    controller: controller.accountController,
                    decoration: const InputDecoration(
                        labelText: "账号",
                        border: OutlineInputBorder()
                    ),
                  ),
                  const SizedBox(height: 12,),
                  TextField(
                    maxLines: 1,
                    controller: controller.passwordController,
                    decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: "密码",
                    ),
                  ),
                  const SizedBox(height: 12,),
                  CheckboxListTile(value: false, onChanged: (bool? value) {
                    // setState(() {
                    //   _isEnableFingerprintLogin = value ?? _isEnableFingerprintLogin;
                    // });
                  },title: const Text("启用指纹登录")),
                  const SizedBox(height: 16,),
                  InkWell(
                    onTap: () async {
                      var account = controller.accountController.text;
                      var password = controller.passwordController.text;
                      // var token = await UserApi.requestLogin(account, password);
                      // if(token!=null){
                      //   StoreApi.instance.storeUserToken(token);
                      //   Map<String, dynamic> tokenInfo= JwtDecoder.decode(token);
                      //   storeUserAccount(tokenInfo['sub']);
                      //   storeBool(StoreKey.isEnableFingerprintLogin, _isEnableFingerprintLogin);
                      //   // TODO Readme
                      //   secureStore(StoreKey.publicKey, account);
                      //   secureStore(StoreKey.privateKey,password);
                      //   context.go("/home");
                      // }
                    },
                    child: Container(
                      padding: const EdgeInsets.symmetric(vertical: 12,horizontal: 8),
                      decoration: const BoxDecoration(
                          color: Colors.blue,
                          borderRadius: BorderRadius.all(Radius.circular(8))
                      ),
                      child: const Center(child: Text("登录", style: TextStyle(fontSize: 16),),),
                    ),
                  )
                ]),
          ),
        )
    );
  }

}